Run a Report with JSON Data in the Java Embedded Engine
This tutorial will guide you through running a document with JSON data in the Java Embedded Engine. It will go over installing the Java Embedded Engine, and setting up the code to run a report with JSON data.
Before installation of the Java Embedded Engine, make sure you meet the requirements and have the necessary pre-requisites installed. Those can be found here.
Install the Java Embedded Engine
There are two ways to install the JAVA Embedded Engine.
- Maven
- Manual Installation with zip file
Maven
To include the Java Engine in your project via Maven, follow the instructions found here.
Manual Installation with zip file
The other approach is referencing the Java Embedded Engine by downloading the zip file which contains the necessary JARs. These can be found on our downloads page here.
Once you have downloaded the zip file, extract the contents and reference the JARs in your project. The steps to do this can be found here.
Setup the Properties
Once you have installed the Java Embedded Engine, you will need to set up the necessary properties in the properties file so you can generate documents. In your projects resources
directory, create a file called "WindwardReports.properties". This file will contain the properties related to document generation. The only property that is required to get started is the license. If this is empty you can still generate output, however it will contain a watermark.
To add your license key or any report properties, you need to add a WindwardReports section to your projects WindwardReports.properties file:
license=[[LICENSE]]
To learn more about the different properties we provide for report generation, check out this article.
Generating a Document
Now that you have the Java Embedded Engine installed and the properties set up, you can start generating documents. Below is an example of how to generate a document with JSON data.
import net.windward.datasource.DataSourceProvider;
import net.windward.datasource.json.JsonDataSource;
import net.windward.xmlreport.ProcessPdf;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class JavaJsonSample {
public static void main(String[] args) {
try {
// To generate a report, first we need a ProcessReport object. For now, we're using the
// pdf format to output.
File fileReport = new File("report.pdf");
FileInputStream template = new FileInputStream("JSON - Template.docx");
FileOutputStream reportStream = new FileOutputStream(fileReport);
ProcessPdf report = new ProcessPdf(template, reportStream);
// Preparation...
report.processSetup();
// Set up the datasource. The parameters are connector package, url, username, password.
// For each type of datasource, the connector package is different
DataSourceProvider datasource = new JsonDataSource("http://json.windward.net/Northwind.json", JsonDataSource.MODE_CONNECTION_STRING);
// Finally, send it to Windward for processing. The second parameter is the name of the
// datasource. This should match the name used in your template.
report.processData(datasource, "JsonData");
// And... DONE!
report.processComplete();
template.close();
reportStream.close();
} catch (Exception e) {
// Uh oh, just in case
e.printStackTrace();
}
}
}